using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace TestCases.Tests.Helpers
{
    
    public class TraceListenerHolder: IDisposable
    {
        private readonly TraceListener[] _oldListeners;
        
        public TraceListenerHolder(TraceListener toSet)
        {
            _oldListeners = new TraceListener[Trace.Listeners.Count];
            Trace.Listeners.CopyTo(_oldListeners,0);
            Trace.Listeners.Clear();
            Trace.Listeners.Add(toSet);
        }
        
        public void Dispose()
        {            
            Trace.Listeners.Clear();
            Trace.Listeners.AddRange(_oldListeners);
        }
    }
    
    public static class TestTrace
    {
    
        public static IDisposable Listener(TraceListener testListener)
        {
            return new TraceListenerHolder(testListener);            
        }
    
        
    }
}